//
//  VisitorView.swift
//  WeiBo
//
//  Created by tusm on 2017/6/17.
//  Copyright © 2017年 GM. All rights reserved.
//

import UIKit
import SnapKit

class VisitorView: UIView {
    
    //MARK: 设置界面信息方法
    func setInfo(imageName:String?, title:String){
        
        messageLabel.text = title
        
        guard let imgName = imageName else {
            
            return
        }
        
        iconImage.image = UIImage(named:imgName)
        
        
    }

    override init(frame:CGRect){
        
        super.init(frame: frame)
        
        setupView()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        //fatalError("init(coder:) has not been implemented")
        
        super.init(coder: aDecoder)
        
        setupView()
    }
    
    //MARK: 懒加载控件
    lazy var iconImage:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    
    lazy var messageLabel:UILabel = UILabel(title: "广告的本质是传播，广告的灵魂是创意。本博意在收罗全球经典广告语；经典广告创意，希望大家支持及参与互动探讨")
    
    lazy var registerButton:UIButton = UIButton(title: "注册", imageName: "new_feature_share_false")
        
    lazy var loginButton:UIButton = UIButton(title: "登陆", imageName: "new_feature_share_false", color: UIColor.darkGray)
    
    
    
    

}

//MARK:视图界面设置
extension VisitorView{
    
    func setupView(){
        
        addSubview(iconImage)
        addSubview(messageLabel)
        addSubview(registerButton)
        addSubview(loginButton)
        
        //        for v in subviews{
        //            
        //            v.translatesAutoresizingMaskIntoConstraints = false
        //        }
                
        //iconImage 自动布局---SnapKit约束方法
        iconImage.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.centerY.equalTo(self.snp.centerY).offset(-70)
            make.width.equalTo(120)
            make.height.equalTo(120)
            
        }
        
        //MARK:苹果自带约束方法
        //        addConstraint(NSLayoutConstraint(item: iconImage, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0))
        //        
        //        addConstraint(NSLayoutConstraint(item: iconImage, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: -70))
        //        addConstraint(NSLayoutConstraint(item: iconImage, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 120))
        //        addConstraint(NSLayoutConstraint(item: iconImage, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 120))
        
        //messageLabel 自动布局
        
        messageLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(iconImage.snp.centerX)
            make.top.equalTo(iconImage.snp.bottom).offset(30)
            make.width.equalTo(300)
        }
        //        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: .centerX, relatedBy: .equal, toItem: iconImage, attribute: .centerX, multiplier: 1.0, constant: 0))
        //        
        //        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: .top, relatedBy: .equal, toItem: iconImage, attribute: .bottom, multiplier: 1.0, constant: 30))
        //        addConstraint(NSLayoutConstraint(item: messageLabel, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 300))
        //       
        
        //registerButton 自动布局
        registerButton.snp.makeConstraints { (make) in
            make.left.equalTo(messageLabel.snp.left)
            make.top.equalTo(messageLabel.snp.bottom).offset(30)
            make.width.equalTo(120)
            make.height.equalTo(40)
        }
        //        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .left, relatedBy: .equal, toItem: messageLabel, attribute: .left, multiplier: 1.0, constant: 0))
        //        
        //        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .top, relatedBy: .equal, toItem: messageLabel, attribute: .bottom, multiplier: 1.0, constant: 30))
        //        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 120))
        //        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 40))
        
        //loginButton 自动布局
        loginButton.snp.makeConstraints { (make) in
            make.right.equalTo(messageLabel.snp.right)
            make.top.equalTo(messageLabel.snp.bottom).offset(30)
            make.size.equalTo(registerButton.snp.size)
        }
        //        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .right, relatedBy: .equal, toItem: messageLabel, attribute: .right, multiplier: 1.0, constant: 0))
        //        
        //        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .top, relatedBy: .equal, toItem: messageLabel, attribute: .bottom, multiplier: 1.0, constant: 30))
        //        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 120))
        //        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 40))
        
        
        
        
        backgroundColor = UIColor(white: 237.0/255.0, alpha: 0.5)
    }
}
































